import React from "react";
import Ionicons from "react-native-vector-icons/Ionicons";
import {
  createAppContainer,
  createBottomTabNavigator,
  createStackNavigator
} from "react-navigation";
import IconWithBadge from "../components/IconWithBadge";

const HomeIconWithBadge = props => {
  // You should pass down the badgeCount in some other ways like context, redux, mobx or event emitters.
  return <IconWithBadge {...props} badgeCount={0} />;
};

const TabNavigator = createBottomTabNavigator(
  {
    喂养记录: require("./record").default,
    周边服务: require("./service").default,
    育儿问答: require("./question").default,
    设置: require("./settings").default
  },
  {
    initialRouteName: "喂养记录",
    defaultNavigationOptions: ({ navigation }) => ({
      tabBarIcon: ({ focused, horizontal, tintColor }) => {
        const { routeName } = navigation.state;
        let IconComponent = Ionicons;
        let iconName;
        if (routeName === "喂养记录") {
          iconName = `ios-home`;
          // Sometimes we want to add badges to some icons.
          // You can check the implementation below.
          IconComponent = HomeIconWithBadge;
        } else if (routeName === "设置") {
          iconName = `ios-options`;
        }

        // You can return any component that you like here!
        return <IconComponent name={iconName} size={25} color={tintColor} />;
      },
      header: null
    }),
    tabBarOptions: {
      activeTintColor: "tomato",
      inactiveTintColor: "gray"
    }
  }
);

const AppNavigator = createStackNavigator(
  {
    AuthLoading: require("./AuthLoadingScreen").default,
    Home: TabNavigator,
    Login: require("./account/Login").default,
    RecordDetail: require("./record/RecordDetail").default,
    AddRecord: require("./record/AddRecord").default,
    AddPerson: require("./record/AddPerson").default,
    AllRecord: require("./record/AllRecord").default,
    About: require("./settings/About").default,
    Feedback: require("./settings/Feedback").default,
    Register: require("./account/Register").default,
    ForgetPassword: require("./account/ForgetPassword").default,
    UpdatePhone: require("./settings/UpdatePhone").default,
    UpdateName: require("./settings/UpdateName").default,
    UpdateEmail: require("./settings/UpdateEmail").default,
    PersonQrCode: require("./record/PersonQrCode").default,
    ScanScreen: require("./record/ScanScreen").default,
    PersonGuardian: require("./record/PersonGuardian").default,
    Share: require("./settings/Share").default
  },
  {
    initialRouteName: "AuthLoading",
    defaultNavigationOptions: {
      header: null
    }
  }
);

export default createAppContainer(AppNavigator);
